#include "GAF_Audio.h"

namespace GAF
{
	Audio::Audio()
	{
		SetChannel_a(GAF_AUDIO_CHANNEL_FREE);
		SetVolume_a(100);
		m_nCurChannel = 0;
	}

	Audio::~Audio()
	{
	}

	bool Audio::OnInit( STD_STRING strMediaFile )
	{
		m_strAudioFile = strMediaFile;
		return true;
	}

	bool Audio::Playing( GAF_CBundle* pbdlParam )
	{
		MediaTransfer _mt = GetMediaTransfer();
		_mt.doing = MEDIA_PLAYING;

		if(GetState_a() == PLAYER_STOP)
		{
			_mt.file = m_strAudioFile;
			_mt.loop = GetLoop_a();
			_mt.channel = GetChannel_a();
			BYTE _bVolume = GetVolume_a();
			if(_bVolume > 100)
				_bVolume = 100;
			_mt.volume = _bVolume;
			_mt.state = PLAYER_STOP;
		}
		else if(GetState_a() == PLAYER_PAUSE)
		{
			_mt.channel = m_nCurChannel;
			_mt.state = PLAYER_PAUSE;
		}
		else
			return false;

		if(!MediaPlayer(_mt))
			return false;

		m_nCurChannel = _mt.channel;
		return true;
	}

	bool Audio::Running(TimeTicks ttUsed, bool& isFinish)
	{
		MediaTransfer _mt = GetMediaTransfer();
		_mt.doing = MEDIA_QUERYING;
		_mt.channel = m_nCurChannel;
		_mt.state = GetState_a();
		MediaPlayer(_mt);

		if(_mt.state == PLAYER_STOP)
			return false;

		return true;
	}

	bool Audio::Pauseing()
	{
		MediaTransfer _mt = GetMediaTransfer();
		_mt.doing = MEDIA_PAUSEING;
		_mt.channel = m_nCurChannel;
		return MediaPlayer(_mt);
	}

	bool Audio::Stopping()
	{
		MediaTransfer _mt = GetMediaTransfer();
		_mt.doing = MEDIA_STOPPING;
		_mt.channel = m_nCurChannel;
		return MediaPlayer(_mt);
	}


}
